package com.shiguiwu.springmybatis.data.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @description: jdbc
 * @author: stone
 * @date: Created by 2022/1/15 13:49
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.jdbc
 */
public class JdbcTests {


    public static void main1(String[] args) throws Exception {
        //加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");

        Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/lunwen?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai",
                "root",
                "123456");

        //PreparedStatement statement = connection.prepareStatement("insert into book(book_name) values (?)");
        PreparedStatement statement =connection.prepareStatement("select * from book");

        //statement.setString(1, "红楼梦");
        statement.executeQuery();


        ResultSet resultSet = statement.getResultSet();

        System.out.println(resultSet);

        while (resultSet.next()) {
            int id = resultSet.getInt("id");
            String name = resultSet.getString("book_name");
            //int id = resultSet.getInt("id");
            System.out.println(id  + "=>" + name);

        }
        resultSet.close();
        statement.close();
        connection.close();
    }


    public static void main(String[] args) throws Exception {
        //加载驱动
        Class.forName("dm.jdbc.driver.DmDriver");

        Connection connection = DriverManager.getConnection("jdbc:dm://192.162.11.205:5236/DATACENTER_USER?zeroDateTimeBehavior=convertToNull&amp;useUnicode=true&amp;characterEncoding=utf-8",
                "DATACENTER_USER",
                "DATACENTER@123");

        //PreparedStatement statement = connection.prepareStatement("insert into book(book_name) values (?)");
        PreparedStatement statement =connection.prepareStatement("select ID from AA");

        //statement.setString(1, "红楼梦");
        statement.executeQuery();


        ResultSet resultSet = statement.getResultSet();


        while (resultSet.next()) {
            String id = resultSet.getString("ID");
            //String name = resultSet.getString("book_name");
            //int id = resultSet.getInt("id");
            System.out.println(id  );

        }

        resultSet.close();
        statement.close();
        connection.close();
    }
}
